package com.sjs.flow.http.advice;

import cn.hutool.core.util.StrUtil;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author uto_dev_008
 * @desc
 * @since 2021/11/24 10:09
 * Copyright (c) 2021 南京友拓信息技术有限公司 All rights reserved
 */
public class UmomLocalResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String l = httpServletRequest.getHeader("language");
        Locale locale = Locale.getDefault();
        if (!StrUtil.isEmpty(l)) {
            String[] split = l.split("_");
            if (split.length >= 2)
                locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
